/*
 *  Copyright 2007-2008 by Matthias Buch-Kromann <mbk.isv@cbs.dk>.
 *  *
 *  This file is part of the Open-source Dependency Toolkit (OSDT),
 *  see http://code.google.com/p/open-source-dependency-toolkit.
 *  
 *  The OSDT is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 * 
 *  The OSDT is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public 
 *  License along with the OSDT in the files COPYING and COPYING.LESSER.
 *  If not, see http://www.gnu.org/licenses.
 */

package org.osdtsystem.demo;

import org.junit.Test;
import org.osdtsystem.exceptions.GraphException;
import org.osdtsystem.graphs.GraphEngine;
import org.osdtsystem.values.EdgeID;
import org.osdtsystem.values.Feature;
import org.osdtsystem.values.Layer;
import org.osdtsystem.values.NodeID;
import org.osdtsystem.values.StringFeature;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class GraphDemo {
    @Test
    public void testSetup() throws GraphException {
        System.out.println("Graph1");
        graph1();
    }

    public static GraphEngine graph1() throws GraphException {
        // Create a new graph for storing the data
        GraphEngine graph = new GraphEngine();

        // Layers
        Layer nodes = graph.addLayer("nodes");
        Layer dependencies = graph.addLayer("edges");
        Layer order = graph.addLayer("order");

        // Create words in graph
        NodeID nodeX = graph.addNode(nodes, "X");
        NodeID nodeGave = graph.addNode(nodes, "gave");
        NodeID nodeY = graph.addNode(nodes, "Y");
        NodeID nodeA = graph.addNode(nodes, "a");
        NodeID nodeGift = graph.addNode(nodes, "gift");

        Feature wordFeature = new StringFeature("word");
        graph.addLayerFeature(nodes, wordFeature);

        graph.setFeatureValue(nodeX, wordFeature, "X");
        graph.setFeatureValue(nodeGave, wordFeature, "gave");
        graph.setFeatureValue(nodeY, wordFeature, "Y");
        graph.setFeatureValue(nodeA, wordFeature, "a");
        graph.setFeatureValue(nodeGift, wordFeature, "gift");

        // Create dependencies
        EdgeID depX = graph.addEdge(nodeX, nodeGave, dependencies);
        EdgeID depY = graph.addEdge(nodeY, nodeGave, dependencies);
        EdgeID depA = graph.addEdge(nodeA, nodeGave, dependencies);
        EdgeID depGift = graph.addEdge(nodeGift, nodeA, dependencies);

        Feature dependencyFeature = new StringFeature("dependency");
        graph.addLayerFeature(dependencies, dependencyFeature);

        graph.setFeatureValue(depX, dependencyFeature, "subj");
        graph.setFeatureValue(depY, dependencyFeature, "iobj");
        graph.setFeatureValue(depA, dependencyFeature, "dobj");
        graph.setFeatureValue(depGift, dependencyFeature, "nobj");

        // Create order edges
        graph.addEdge(nodeGave, nodeX, order);
        graph.addEdge(nodeY, nodeGave, order);
        graph.addEdge(nodeA, nodeY, order);
        graph.addEdge(nodeGift, nodeA, order);

        // Return graph
        return graph;
    }        
}
